package com.zhangwei.touch.fragment;


import android.graphics.BitmapFactory;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.zhangwei.touch.R;
import com.zhangwei.touch.vpi.adapter.ImageAdapter;
import com.zhangwei.touch.widget.MyViewPage;

import org.androidannotations.annotations.AfterInject;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */

@EFragment(R.layout.fragment_image)
public class ImageFragment extends Fragment {
    @ViewById
    MyViewPage imgVp;
    private List<View> views;
    private int[] resIds = {R.mipmap.a1, R.mipmap.a2, R.mipmap.a3, R.mipmap.a4};

    @AfterInject
    public void inject() {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 8;
        views = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            ImageView img = new ImageView(getActivity());
            img.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
            img.setImageBitmap(BitmapFactory.decodeResource(getResources(), resIds[i], options));
            views.add(img);
        }
    }

    @AfterViews
    public void initView() {
        ImageAdapter adapter = new ImageAdapter(views);
        imgVp.setAdapter(adapter);
    }
}
